package com.stylefeng.guns.modular.system.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.KnowledgeBase;
import com.stylefeng.guns.modular.system.service.IKnowledgeBaseService;

/**
 * 知识库控制器
 *
 * @author fengshuonan
 * @Date 2019-10-07 01:37:50
 */
@Controller
@RequestMapping("/knowledgeBase")
public class KnowledgeBaseController extends BaseController {

    private String PREFIX = "/system/knowledgeBase/";

    @Autowired
    private IKnowledgeBaseService knowledgeBaseService;

    /**
     * 跳转到知识库首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "knowledgeBase.html";
    }

    /**
     * 跳转到添加知识库
     */
    @RequestMapping("/knowledgeBase_add")
    public String knowledgeBaseAdd() {
        return PREFIX + "knowledgeBase_add.html";
    }

    /**
     * 跳转到修改知识库
     */
    @RequestMapping("/knowledgeBase_update/{knowledgeBaseId}")
    public String knowledgeBaseUpdate(@PathVariable Integer knowledgeBaseId, Model model) {
        KnowledgeBase knowledgeBase = knowledgeBaseService.selectById(knowledgeBaseId);
        model.addAttribute("item",knowledgeBase);
        LogObjectHolder.me().set(knowledgeBase);
        return PREFIX + "knowledgeBase_edit.html";
    }

    /**
     * 获取知识库列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return knowledgeBaseService.selectList(null);
    }

    /**
     * 新增知识库
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(KnowledgeBase knowledgeBase) {
        knowledgeBaseService.insert(knowledgeBase);
        return SUCCESS_TIP;
    }

    /**
     * 删除知识库
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer knowledgeBaseId) {
        knowledgeBaseService.deleteById(knowledgeBaseId);
        return SUCCESS_TIP;
    }

    /**
     * 修改知识库
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(KnowledgeBase knowledgeBase) {
        knowledgeBaseService.updateById(knowledgeBase);
        return SUCCESS_TIP;
    }

    /**
     * 知识库详情
     */
    @RequestMapping(value = "/detail/{knowledgeBaseId}")
    @ResponseBody
    public Object detail(@PathVariable("knowledgeBaseId") Integer knowledgeBaseId) {
        return knowledgeBaseService.selectById(knowledgeBaseId);
    }
    /**
     * 查询所有知识库列表
     */
    @RequestMapping(value = "/searchAll")
    @ResponseBody
    public Object searchAll() {
        return knowledgeBaseService.searchAll();
    }
}
